{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from gs_quant.instrument import FXBinary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from gs_quant.session import GsSession\n",
    "\n",
    "# external users should substitute their client id and secret\n",
    "GsSession.use(client_id=None, client_secret=None, scopes=('run_analytics'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "FXBinary?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "binary = FXBinary(pair='USDJPY', buy_sell='Buy', expiration_date='3m')\n",
    "binary.resolve()\n",
    "print(binary.as_dict())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Strike Price \n",
    "\n",
    "If the strike price is not specified, the current spot is used as the default. Similar to FXOption, the strike price can be specified by a double or a string.\n",
    "\n",
    "\n",
    "The specific solver keys are: \n",
    "\n",
    "    - 'S'    - current spot rate\n",
    "    - 'F'    - forward\n",
    "    - 'P'    - Premium\n",
    "    - 'D'    - Delta    \n",
    "\n",
    "You can use these keys to strike_price with the following formats: \n",
    "\n",
    "    - For S, F: 's*1.1', 'F+10%' \n",
    "    - For Delta Strikes, specify the option delta: '25D', '20D-.01', etc.\n",
    "    - You can also solve for Premium:  P={target}%\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "Instrument - Solving - FX Binary strike solving",
     "Metrics - FXSpot"
    ]
   },
   "outputs": [],
   "source": [
    "from gs_quant.risk import FXSpot, FXFwd\n",
    "\n",
    "# solve for strike price by setting payout ratio to 10%\n",
    "binary_10x = FXBinary(\n",
    "    pair='EURUSD', buy_sell='Buy', option_type='Put', expiration_date='1m', strike_price='p=10%', premium=0\n",
    ")\n",
    "binary_10x.resolve()\n",
    "print('strike price:', binary_10x.strike_price)\n",
    "print('spot level:', binary_10x.calc(FXSpot))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "binary_itm = FXBinary(pair='AUDUSD', buy_sell='Buy', expiration_date='3m', strike_price='1.1*s')\n",
    "binary_itm.resolve()\n",
    "print('strike price:', binary_itm.strike_price)\n",
    "print('spot level:', binary_itm.calc(FXSpot))\n",
    "binary_itm.calc(FXSpot) * 1.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "Metrics - FXFwd"
    ]
   },
   "outputs": [],
   "source": [
    "binary_otm = FXBinary(pair='AUDUSD', buy_sell='Buy', expiration_date='3m', notional_amount='100k', strike_price='F-2%')\n",
    "binary_otm.resolve()\n",
    "print('strike price:', binary_otm.strike_price)\n",
    "print('fwd level:', binary_otm.calc(FXFwd))\n",
    "binary_otm.calc(FXFwd) * 0.98"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  },
  "tags": [
   "Instrument - FXBinary"
  ]
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
